#coding:utf-8
import os
import sys
from pandas import DataFrame
from bridge import SSHConnection
sys.path.insert(0,r'D:\tmp\speedreport')

class GetData(object):
	"""docstring for GetData"""
	def __init__(self):
		super(GetData, self).__init__()	
		self.conn = SSHConnection("10.175.113.73",22,"root","huawei")
		self.rootdir = os.getcwd()

	def get_txt(self):
		'''
		    download txt
		'''
		try:
			pathlist = self.conn.exec_command("ls ../home/test/zhangyi/SpeedIndex/get_result/").strip().split('\n')
			for i in pathlist:
				self.conn.download('/home/test/zhangyi/SpeedIndex/get_result/%s'%i,os.path.join(self.rootdir,'txtfile',i))
		except Exception, e:
			raise e
		

	def put_list(self):
		try:
			l1 = []
			# self.get_txt()
			txtlist =  os.listdir(os.path.join(os.getcwd(),'txtfile'))
			print txtlist
			for i in txtlist:
				if '.py' in i:
					continue
				l1.append(i.split('_')[0])
			webname = sorted(set(l1),key=l1.index)
			return webname
		except Exception, e:
			raise e

	# def read_txt(self):
	# 	fns = [os.path.join(root, fn) for root, dirs, files in os.walk(self.rootdir) for fn in files]
	# 	for i in fns:
	# 		print i

	# def test_read(self):
	# 	with open(r'D:\Speed_Index\result\weibo.com_uc.txt','r') as f:
	# 		string= f.read().split(':')
	#         speedIndex=string[2].split(' ') [0]
	#         print speedIndex
	#         totalTime =string[3]
	#         print totalTime
# GetData().get_txt()